package pack

import (
	"pay_service/biz/model"
	"pay_service/biz/model/orm_gen"

	"google.golang.org/protobuf/types/known/timestamppb"
)

func PayOrder(ormModel *orm_gen.PayOrder) *model.PayOrderDTO {
	if ormModel == nil {
		return nil
	}
	return &model.PayOrderDTO{
		Id:             ormModel.ID,
		BizOrderNo:     ormModel.BizOrderNo,
		PayOrderNo:     ormModel.PayOrderNo,
		BizUserId:      ormModel.BizOrderNo,
		PayChannelCode: ormModel.PayChannelCode,
		Amount:         ormModel.Amount,
		PayType:        ormModel.PayType,
		ExpandJson:     ormModel.ExpandJSON,
		ResultCode:     ormModel.ResultCode,
		ResultMsg:      ormModel.ResultMsg,
		PaySuccessTime: timestamppb.New(ormModel.PaySuccessTime),
		PayOverTime:    timestamppb.New(ormModel.PayOverTime),
		CreateTime:     timestamppb.New(ormModel.CreateTime),
		UpdateTime:     timestamppb.New(ormModel.UpdateTime),
	}
}

func PayOrders(ormModel []*orm_gen.PayOrder) []*model.PayOrderDTO {
	payOrders := make([]*model.PayOrderDTO, len(ormModel))
	for _, m := range ormModel {
		if p := PayOrder(m); p != nil {
			payOrders = append(payOrders, p)
		}
	}
	return payOrders
}

func QueryPayOrderByBizOrderNoResponse(dtoModel *model.PayOrderDTO) *model.QueryPayOrderByBizOrderNoResponse {
	return (*model.QueryPayOrderByBizOrderNoResponse)(dtoModel)
}
